<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>个人设置</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta content="telephone=no,email=no,address=no" name="format-detection" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="msapplication-tap-highlight" content="no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="wap-font-scale" content="no">
		<meta name="Keywords" content="用户中心" />
		<meta name="Description" content="用户中心" />
		<link rel="stylesheet" href="__TMPL__Public/css/common.css" />
		<link rel="stylesheet" href="__TMPL__Public/css/user.css" />
		<link rel="stylesheet" href="__TMPL__Public/css/public.css" />

		<style>
			.header {
				position: relative;
				width: 100%;
				height: 50px;
				background: #fafafa;
				zoom: 1;
				border-bottom: 1px solid #eee;
			}
		</style>
		
		<php>
			$agent=$_SERVER['HTTP_USER_AGENT'];
			if(strpos($agent,"Html5Plus")> -1){
		</php>
		<script type="text/javascript">
		var auths=null;
		// 监听plusready事件  
		document.addEventListener( "plusready", function(){
			// 扩展API加载完毕，现在可以正常调用扩展API
			plus.oauth.getServices( function(services){
				auths = services;
			}, function(e){
				document.getElementById('weixin_login').style.display='none';
			} );
		}, false );
		</script>
		<php>
		}
		</php>
	</head>

	<body>
		<input type="file"  accept="image/*" name="logo" id="upload_pic" style="display: none;">
		<div class="user-info-box">

			<header>
				<div class="header">
					<div class="header-left">
						<a class="sb-back" href="{:U('user/center')}" title="返回"></a>
					</div>
					<div class="header-middle">个人设置</div>
					<div class="header-right">
						<aside class="show-menu-btn">
							<div class="show-menu" id="show_more">
								<a href="javascript:void(0);"></a>
							</div>
						</aside>
					</div>
				</div>
			</header>
			<mtc_include file="Public:right_nav" />
			
			<dl class="upload-image" style="cursor: pointer;"  onclick = "clp();">
				<dt class="user-logo"><h3>头像</h3>
					<h5>
						
						<img src="{$user_info.user_pic}">
						<i class="iconfont"></i>
					</h5>
				</dt>
			</dl>
			<dl>
				<dt>
					<h3>手机</h3>
					<h5 onclick="location.href='/user/change_phone'">
						{$user_info.phone}
						<i class="iconfont"></i>
					</h5>
				</dt>
			</dl>
			<dl class="nickname_dl">
				<dt>
					<h3>昵称</h3>
					<h5>
						{$user_info.username}
						<i class="iconfont"></i>
					</h5>
				</dt>
			</dl>
			<dl class="sex_dl">
				<dt>
					<h3>性别</h3>
					<h5>
						<eq name="user_info.sex" value="0">保密</eq>
						<eq name="user_info.sex" value="1">男</eq>
						<eq name="user_info.sex" value="2">女</eq>
						<i class="iconfont"></i>
					</h5>
				</dt>
			</dl>
			<dl class="birthday_dl" id="showbirth">
				<dt>
					<h3>出生日期</h3>
					<h5>
						<input id="birth" value="{$user_info.birthday}" class="mbsc-comp" readonly="">
						<i class="iconfont"></i>
					</h5>
				</dt>
			</dl>
			<div class="uset-center-content" style=" margin-top: 51px;">
				<a href="javascript:;" onclick="login_out();">

					<dl style="width:100%;text-align:center;background:red;">
						<dt style="width:100%;text-align:center;color: #fff;">退出登录</dt>
					</dl>
				</a>
			</div>
		</div>
		
		<div id="user_nickname">
			<header>
				<div class="tab_nav">
					<div class="header">
						<div class="header-left">
							<a class="sb-back" href="{:U('user/info')}" title="返回"></a>
						</div>
						<div class="header-middle">修改昵称</div>
						<div class="header-right">
							<a href="javascript:void(0)" class="btn-submit text">确定</a>
						</div>
					</div>
				</div>
			</header>
			<div class="middle-content">
				<div class="form-group-box">
					<div class="form-group form-group-spe">
						<dl>
							<dt>
							<span>昵称：</span>
							</dt>
							<dd>
								<div class="form-control-box">
									<input type="text" id="nickname" class="form-control" name="nickname" value="{$user_info.username}"  placeholder="输入您的昵称" >
								</div>
							</dd>
						</dl>
					</div>
				
				</div>
			</div>
		</div>

		<div id="user_sex_box">
			<header>
				<div class="header">
					<div class="header-left">
						<a class="sb-back" href="{:U('user/info')}" title="返回"></a>
					</div>
					<div class="header-middle">修改性别</div>
					<div class="header-right">
						<a href="javascript:void(0)" class="btn-submit text">确定</a>
					</div>
				</div>
			</header>
			<input type="hidden" id="user_sex" name="user_sex" value="{$user_info.sex}">
			<ul class="user-sex">
				<li>
					<span data-sex="0" <eq name="user_info.sex" value="0">class="selected"</eq>>保密</span>
				</li>
				<li>
					<span data-sex="1" <eq name="user_info.sex" value="1">class="selected"</eq>>男</span>
				</li>
				<li>
					<span data-sex="2" <eq name="user_info.sex" value="2">class="selected"</eq>>女</span>
				</li>
			</ul>
		</div>

		<script type="text/javascript" src="__TMPL__Public/js/jquery.js"></script>
		<script type="text/javascript" src="__TMPL__Public/js/common.js"></script>
		<script src="/themes/wnsc_moblie/newMobile/User/js/mobiscroll/mobiscroll.custom-3.0.0-beta.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="/themes/wnsc_moblie/newMobile/User/js/mobiscroll/mobiscroll.custom-3.0.0-beta.min.css"/>
		<script src="/themes/wnsc_moblie/newMobile/User/login/js/mobile/layer.js"></script>
		<script src="/themes/wnsc_moblie/newMobile/User/js/lrz.all.bundle.js"></script>
	
		<php>
			$agent=$_SERVER['HTTP_USER_AGENT'];
			if(strpos($agent,"Html5Plus")> -1){
		</php>
		<script type="text/javascript">
			function login_out(){
				for ( var i in auths ) {
					var s = auths[i];
					if ( s.authResult ) {
						s.logout(function(e){
							
						}, function(e){
							
						});
					}
				}
				setTimeout("window.location.href='{:U("user/login_out")}'",1000)
			}
		</script>
		<php>
		}else{
		</php>
		<script type="text/javascript">
			function login_out(){
				setTimeout("window.location.href='{:U("user/login_out")}'",0)
			}
		</script>
		<php>
			}
		</php>
		<script type="text/javascript">
			var step = 0;

			$('.nickname_dl').click(function() {
				step = 2;
				$('#user_nickname').show();
				$('.user-info-box').hide();
			});
			$('.sex_dl').click(function() {
				step = 3;
				$('#user_sex_box').show();
				$('.user-info-box').hide();
			});
			$('.user-sex li span').click(function() {
				$(this).addClass('selected').parents("li").siblings().find('span').removeClass('selected');
				$("#user_sex").val($(this).data('sex'));
			});

			$('.btn-submit').click(function(){
				var nickname=$('#nickname').val();
				var user_sex=$('#user_sex').val();
				$.post("/user/info", {
					nickname: nickname,
					user_sex: user_sex
				}, function(result) {
					if(result.code==1){
						showErrorMsg(result.message);
						setTimeout('location.reload();',1000);
					}
					if(result.code==0){
						setTimeout('location.reload();',0);
					}
				}, "json");
			})
			
			/*生日选择*/
			$(function() {
				var currYear = new Date().getFullYear();
				//alert(new Date(new Date().setFullYear(currYear - 20)));
				$('#birth').mobiscroll().date({
					theme: 'mobiscroll',
					lang: 'zh',
					display: 'center',
					dateFormat: 'yy-mm-dd', // 日期格式
					//下面这句是默认显示20年前的日期
					//defaultValue: new Date(new Date().setFullYear(currYear - 20)),
					//如果会员设置过生日，则defaultValue设置为他的生日；
					defaultValue: new Date("2009-02-03"),
					max: new Date(),
					min: new Date('1970-01-02'),
					onSet: function(data) {
						$.post("/user/editprofile", {
							item: 'birthday',
							value: $("#birth").val(),
							title: '出生日期'
						}, function(result) {
							if(result.code == 1) {
								showErrorMsg(result.message);
							}
						}, "json");
					}
				});

			});
			
			
			
	
			  $("#upload_pic").change(function () {
		        /* 压缩图片 */
		        lrz(this.files[0], {
		            width: 300 //设置压缩参数
		        }).then(function (rst) {
		            /* 处理成功后执行 */
		            rst.formData.append('base64img', rst.base64); // 添加额外参数
		            $.ajax({
		                url: "{:U('user/uploadify_wb')}",
		                type: "POST",
		                data: rst.formData,
		                processData: false,
		                contentType: false,
		                success: function (data) {
		              		data= data.replace("\/", "");
		                	data = eval("(" + data + ")"); 
		                	
		                   var src='/'+data.saveURL;
		                   $('.user-logo h5 img').attr('src',src);
		                   $.post("/user/editprofile", {
							item: 'headimg',
							value: src
							
							}, function(result) {
								if(result.code == 1) {
									showErrorMsg(result.message);
									
								}
							}, "json");
		                }
		            });
		        }).catch(function (err) {
		            /* 处理失败后执行 */
		        }).always(function () {
		            /* 必然执行 */
		        })
		    })
			
			function clp(){
			   return  $("#upload_pic").click();
			}
			function showErrorMsg(msg) {

				layer.open({
					content: msg,
					time: 2
				});
			}
		</script>
	</body>

</html>